package cn.xuziao.databasecourse.controller;

import cn.xuziao.databasecourse.pojo.FeedBacKInfo;
import cn.xuziao.databasecourse.pojo.SimpleInfo;
import cn.xuziao.databasecourse.service.GetModelAndView;
import cn.xuziao.databasecourse.service.Search;
import cn.xuziao.databasecourse.tools.SendIdentifyingCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;

/**
 * @author xuziao
 * @date 2021/11/17 8:33
 */
@Controller
@Slf4j
public class ServiceController {

    Search search;
    GetModelAndView getModelAndView;

    @Autowired
    public ServiceController(Search search, GetModelAndView getModelAndView) {
        this.search = search;
        this.getModelAndView = getModelAndView;
    }



    @GetMapping("/simpleInfoSearch/{info}")
    public ModelAndView simpleInfoSearch(@PathVariable("info") String info) {
        List<SimpleInfo> simpleInfos = search.searchImgPath(info);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("simpleInfos", simpleInfos);
        modelAndView.setViewName("testmav");
        System.out.println(simpleInfos);
        return modelAndView;
    }

    @RequestMapping("/submitService")
    public ModelAndView submit(@ModelAttribute FeedBacKInfo feedBacKInfo){
        System.out.println(feedBacKInfo);
        String manager = feedBacKInfo.getManager();
        HashMap<String, String> emails = new HashMap<String, String>();
        emails.put("2734307083@qq.com", "卢慧婷");
        emails.put("1967453345@qq.com", "刘淑");
        emails.put("2352505299@qq.com", "何佳涛");
        emails.put("286748439@qq.com", "罗仕睿");
        emails.put("lht", "2734307083@qq.com");
        emails.put("ls", "1967453345@qq.com");
        emails.put("hjt", "2352505299@qq.com");
        emails.put("xza", "750133671@qq.com");
        emails.put("lsr", "286748439@qq.com");
        SendIdentifyingCode.send(emails.get(manager), SendIdentifyingCode.format(feedBacKInfo));
        return getModelAndView.getIndexModelAndView();
    }


    @GetMapping("/image")
    public ModelAndView images(){
        ModelAndView modelAndView = new ModelAndView();
        List<SimpleInfo> images = search.getAllImages();
        modelAndView.addObject("images", images);
        modelAndView.setViewName("imgshow");
        return modelAndView;
    }

    @GetMapping("/allCnkis")
    public ModelAndView allCnkis() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("allCnkisInfo", search.getAllCnkis());
        modelAndView.setViewName("The hownet paper");
        return modelAndView;
    }
}
